//
//  WZTabBarViewController.swift
//  weiBo---01
//
//  Created by 王—wagn on 16/4/6.
//  Copyright © 2016年 王—wagn. All rights reserved.
//

import UIKit

class WZTabBarViewController: UITabBarController {

    
    @objc private func pultBtnDidClick() {
        print("撰写按钮被点击啦")
    }
    override func viewDidLoad() {
        super.viewDidLoad()

        
        
        let mainTabBar = WZTabBar()
        
        mainTabBar.pultBtn .addTarget(self, action: "pultBtnDidClick", forControlEvents: .TouchUpInside)
       
        //点击方法是私有,不让外部访问,需要要使用private 必须在前面增加@objc
//        @objc private func pultBtnDidClick() {
//            print("好好好好")
//        }
        
        print(tabBar.classForCoder)

        setValue(mainTabBar, forKey: "tabBar")
        print(tabBar.classForCoder)

        addChildViewController()
    
    }
    
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        
    }
    

    
     //创建
     private func addChildViewController() {
        
        addChildViewController(WZHomeViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(WZMessageController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(WZDiscoverViewController(), title: "发现", imageName:  "tabbar_discover")
        addChildViewController(WZProfileViewController(), title: "我的", imageName: "tabbar_profile")
        
        
    }
    
    //封装方法
    private func addChildViewController(vc:UITableViewController, title:String, imageName:String) {
        
        //会把文字和颜色同时设置,如果需要不同效果,需要用下面方法
//      tabBar.tintColor = UIColor.orangeColor()
//        let vc = UIViewController()
        
        vc.title = title
        
        vc.tabBarItem.title = title
        
        vc.tabBarItem.image = UIImage(named: imageName)
        //设置选中图片
        vc.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        //设置字体颜色
        vc .tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.redColor()], forState: .Selected)
        
        let nav = WZBackTitleViewController(rootViewController:vc)
        
        addChildViewController(nav)
        
    }

}
